package com.example.backend.mapper;


import com.example.backend.entity.Dishes;
import com.example.backend.util.StringUtil;

public class DishesMapperProvider {
    public String getSelectDishesSql(Dishes dishes){
        StringBuilder sql = new StringBuilder();
        sql.append("select * from dishes where 1=1");
        if(dishes.getId() != null){
            sql.append(" and id = #{id}");
        }
        if(StringUtil.isNotEmpty(dishes.getName())){
            sql.append(" and name like concat('%',#{name},'%')");
        }
        if(dishes.getShop_id() != null){
            sql.append(" and shop_id like concat('%',#{shop_id},'%')");
        }
        if(dishes.getPrice() != null){
            sql.append(" and price like concat('%',#{price},'%')");
        }
        if(StringUtil.isNotEmpty(dishes.getState())){
            sql.append(" and state like concat('%',#{state},'%')");
        }
        if(StringUtil.isNotEmpty(dishes.getDishes_class())){
            sql.append(" and dishes_class like concat('%',#{dishes_class},'%')");
        }
        return sql.toString();
    }

    public String getUpdateDishesSql(Dishes dishes){
        StringBuilder sql = new StringBuilder();
        sql.append("update dishes set id =#{id}");
        if(dishes.getName() != null){
            sql.append(" ,name = #{name}");
        }
        if(dishes.getShop_id() != null){
            sql.append(" ,shop_id = #{shop_id}");
        }
        if(dishes.getPrice() != null){
            sql.append(" ,price = #{price}");
        }
        if(dishes.getState() != null){
            sql.append(" ,state = #{state}");
        }
        if(dishes.getDishes_class() != null){
            sql.append(" ,dishes_class = #{dishes_class}");
        }
        if(dishes.getPicture() != null){
            sql.append(" ,picture = #{picture}");
        }
        sql.append(" where id = #{id}");
        return sql.toString();
    }

}
